import math, sys
input = lambda: sys.stdin.readline().strip()
def lcm(a, b):
return a * b // math.gcd(a, b)
n, a, b, p, q = [int(x) for x in input().split()]
num_div_a = n // a
num_div_b = n // b
num_div_ab = n // (lcm(a, b))
print((num_div_a - num_div_ab) * p + (num_div_b - num_div_ab) * q + num_div_ab * max(p, q))
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265359
#define dmin 1e-9
#define dd double
#define ll long long
#define pq priority_queue
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define in insert
#define vpi vector<pair<int,int>>
#define fori for(int i=0;i<n;i++)
#define srt v.begin(),v.end()
#define all(v) v.begin(),v.end()
#define nl "\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL);
void mdmerazulislam()
{
}
int main()
{
fast;
ll n,a,b,p,q;
cin>>n>>a>>b>>p>>q;
ll ans=0;
ans += ((n/a) *p);
ans += ((n/b) *q);
ll gcd = __gcd(a,b);
ll lcm = (a/(gcd)*b);
ll same ;
same= n/lcm;
ans -= (same*(p+q));
ans +=(same*(max(p,q)));
cout<<ans<<endl;
return 0;
}
1B - Spreadsheet | 1177A - Digits Sequence (Easy Edition) |
1579A - Casimir's String Solitaire | 287B - Pipeline |
510A - Fox And Snake | 1520B - Ordinary Numbers |
1624A - Plus One on the Subset | 350A - TL |
1487A - Arena | 1520D - Same Differences |
376A - Lever | 1305A - Kuroni and the Gifts |
1609A - Divide and Multiply | 149B - Martian Clock |
205A - Little Elephant and Rozdil | 1609B - William the Vigilant |
978B - File Name | 1426B - Symmetric Matrix |
732B - Cormen --- The Best Friend Of a Man | 1369A - FashionabLee |
1474B - Different Divisors | 1632B - Roof Construction |
388A - Fox and Box Accumulation | 451A - Game With Sticks |
768A - Oath of the Night's Watch | 156C - Cipher |
545D - Queue | 459B - Pashmak and Flowers |
1538A - Stone Game | 1454C - Sequence Transformation |